﻿using System;
using com.yoozoo.gta.Extension.UGUI.ScreenOrientationEx;
using UnityEngine;
using UnityEngine.UI;

namespace com.yoozoo.gta.Extension.UGUI.ScreenOrientation.Adapter
{
    
    
    [Serializable]
    public class HorizontalOrVerticalLayoutGroupAdaptConfig
    {
        public RectOffset padding;
        public float Spacing;
        public TextAnchor childAlignment;
        public bool childControlWidth;
        public bool childControlHeight;
        public bool childScaleWidth;
        public bool childScaleHeight;
        public bool childForceExpandWidth;
        public bool childForceExpandHeight;
        
        //重写Equals方法
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return false;
            }

            HorizontalOrVerticalLayoutGroupAdaptConfig other = (HorizontalOrVerticalLayoutGroupAdaptConfig)obj;
            //对比下面属性是否一致
            if (padding.left != other.padding.left || padding.right != other.padding.right || padding.top != other.padding.top || padding.bottom != other.padding.bottom)
            {
                return false;
            }

            // Compare Spacing properties
            if (Spacing != other.Spacing)
            {
                return false;
            }
            
            // Compare childAlignment properties
            if (childAlignment != other.childAlignment)
            {
                return false;
            }
            
            // Compare childControlWidth properties
            if (childControlWidth != other.childControlWidth)
            {
                return false;
            }
            
            // Compare childControlHeight properties
            if (childControlHeight != other.childControlHeight)
            {
                return false;
            }
            
            // Compare childScaleWidth properties
            if (childScaleWidth != other.childScaleWidth)
            {
                return false;
            }
            
            // Compare childScaleHeight properties
            if (childScaleHeight != other.childScaleHeight)
            {
                return false;
            }
            
            // Compare childForceExpandWidth properties
            if (childForceExpandWidth != other.childForceExpandWidth)
            {
                return false;
            }
            
            // Compare childForceExpandHeight properties
            if (childForceExpandHeight != other.childForceExpandHeight)
            {
                return false;
            }
            
            return true;
        }
        
        //重写GetHashCode方法
        public override int GetHashCode() {
            int hash = 17;
            hash = hash * 23 + padding.GetHashCode();
            hash = hash * 23 + Spacing.GetHashCode();
            hash = hash * 23 + childAlignment.GetHashCode();
            hash = hash * 23 + childControlWidth.GetHashCode();
            hash = hash * 23 + childControlHeight.GetHashCode();
            hash = hash * 23 + childScaleWidth.GetHashCode();
            hash = hash * 23 + childScaleHeight.GetHashCode();
            hash = hash * 23 + childForceExpandWidth.GetHashCode();
            hash = hash * 23 + childForceExpandHeight.GetHashCode();
            return hash;
        }

    }
    [DisallowMultipleComponent]
    public class HorizontalLayoutGroupAdapt: AdaptBase<HorizontalOrVerticalLayoutGroupAdaptConfig, HorizontalLayoutGroup>
    {
        public override int Order => (int)AdapterExecuteOrder.ListView;
        protected override void ApplyConfig(HorizontalOrVerticalLayoutGroupAdaptConfig config)
        {
            base.ApplyConfig(config);
            mComponent.childAlignment = config.childAlignment;
            mComponent.padding.left = config.padding.left;
            mComponent.padding.right = config.padding.right;
            mComponent.padding.top = config.padding.top;
            mComponent.padding.bottom = config.padding.bottom;
            mComponent.spacing = config.Spacing;
            mComponent.childAlignment = config.childAlignment;
            mComponent.childControlWidth = config.childControlWidth;
            mComponent.childControlHeight = config.childControlHeight;
            mComponent.childScaleWidth = config.childScaleWidth;
            mComponent.childScaleHeight = config.childScaleHeight;
            mComponent.childForceExpandWidth = config.childForceExpandWidth;
            mComponent.childForceExpandHeight = config.childForceExpandHeight;
            
        }
  
        protected override void CopyProperty(HorizontalOrVerticalLayoutGroupAdaptConfig config) 
        {
            base.CopyProperty(config);  
            config.padding = new RectOffset(mComponent.padding.left, mComponent.padding.right, mComponent.padding.top, mComponent.padding.bottom);    
            config.childAlignment = mComponent.childAlignment;
            config.Spacing = mComponent.spacing;
            config.childAlignment = mComponent.childAlignment;
            config.childControlWidth = mComponent.childControlWidth;
            config.childControlHeight = mComponent.childControlHeight;
            config.childScaleWidth = mComponent.childScaleWidth;
            config.childScaleHeight = mComponent.childScaleHeight;
            config.childForceExpandWidth = mComponent.childForceExpandWidth;
            config.childForceExpandHeight = mComponent.childForceExpandHeight;
            
        }
    }

    
}